package com.xhs.main.controller.cwb;

import com.alibaba.fastjson.JSONArray;
import com.xhs.main.service.cwb.impl.CwbPaytaxesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * create by ljw on 2020/10/22
 */
@Controller
public class AmountController {

    @Autowired
    CwbPaytaxesServiceImpl cwbPaytaxesService;

    //税务支出(柱状图)
    @RequestMapping("/expenditure")
    @ResponseBody
    public String getAllExpenditure(){
        List<Map<String,Object>> mapList = new ArrayList<>();
        //优化过后的税收信息
        for(int i = 1;i<11;i++){
            Map<String,Object> map = new HashMap<>();
            Double money = 0.0;
            map.put("name",i+"月15日");
            if (i == 10) {
                //当月份达到10后不做判断会有bug
                money = cwbPaytaxesService.getAllMoney("2020-"+i);
            }else{
                money = cwbPaytaxesService.getAllMoney("2020-0"+i);
            }
            map.put("value",money);
            mapList.add(map);
        }
        //返回的数据
        String json = JSONArray.toJSONString(mapList);
        return json;
    }

    //季度税务支出(玫瑰饼图)
    @RequestMapping("/jiduexpenditure")
    @ResponseBody
    public String getAllExpenditurejidu(){
        List<Map<String,Object>> mapList = new ArrayList<>();
        Map<String,Object> map1 = new HashMap<>();
        Map<String,Object> map2 = new HashMap<>();
        Map<String,Object> map3 = new HashMap<>();
        Map<String,Object> map4 = new HashMap<>();
        map1.put("name","一季度");
        map1.put("value",cwbPaytaxesService.getAllMoney("2020-10-15"));
        map4.put("name","四季度");
        map4.put("value",cwbPaytaxesService.getjidumoney("2020-01-15","2020-03-15"));
        map2.put("name","二季度");
        map2.put("value",cwbPaytaxesService.getjidumoney("2020-04-15","2020-06-15"));
        map3.put("name","三季度");
        map3.put("value",cwbPaytaxesService.getjidumoney("2020-07-15","2020-09-15"));

        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);
        mapList.add(map4);
        //返回的数据
        String json = JSONArray.toJSONString(mapList);
        return json;
    }
}
